#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time      :2021/11/8 10:54
# @Author    :cjw
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
from use_httprunner_api.testcases.token_test import TestToken
from use_httprunner_api.setting import FEISHU_URL


class TestCreate(HttpRunner):
	config = (
		Config("创建日历")
			.verify(False)
			.variables(**{
			"timestamp": "${get_timestamp()}"
		})
			.base_url(FEISHU_URL)
	)

	teststeps = [
		Step(
			RunTestCase("获取token")
				.call(TestToken)
				.export("token")
		),
		Step(
			RunRequest("创建日历")
				.post("/calendars")
				.with_headers(
				**{
					"Authorization": "Bearer $token",
					"Content-Type": "application/json; charset=utf-8"
				}
			)
				.with_json(
				{
					"summary": "测试日历_$timestamp",
					"description": "使用开放接口创建日历_$timestamp",
					"permissions": "public",
					"color": -1,
					"summary_alias": "日历备注名_$timestamp"
				}
			)
				.validate()
				.assert_equal("status_code", 200)
				.assert_equal("body.code", 0)
		)
	]


if __name__ == '__main__':
	TestCreate().test_start()
